package com.feiluan.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;


@Component
public class BasicService {

    @Autowired
    private RestTemplate restTemplate;

    public <T> ResponseEntity<T> postProxy(String uri, HttpHeaders headers, Object body, Class<T> responseType) {
        HttpEntity request = new HttpEntity<>(body, headers);
        ResponseEntity<T> responseEntity = restTemplate.postForEntity(uri, request, responseType);
        return responseEntity;
    }

    public <T> ResponseEntity<T> getProxy(String uri, HttpHeaders headers, Class<T> responseType) {
        HttpEntity request = new HttpEntity<>(headers);
        ResponseEntity<T> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, request, responseType);
        return responseEntity;
    }
}
